package com.db.williamchart.renderer.executor;

import com.db.williamchart.data.Frame;
import ohos.utils.Pair;

import java.util.ArrayList;
import java.util.List;

public class DefineDataPointsClickableFrames {

    public List<Frame> invoke(Frame innerFrame, List<Pair<Float,Float>> datapointsCoordinates,int clickableRadius){
        int size = datapointsCoordinates.size();
        float halfWidthBetweenLabels =
                ((innerFrame.getRight() - innerFrame.getLeft()) / (size - 1)) / 2;

        List<Frame> frames = new ArrayList<>(size);

        for (Pair<Float, Float> datapointsCoordinate : datapointsCoordinates) {
            float left = clickableRadius > halfWidthBetweenLabels ? datapointsCoordinate.f - halfWidthBetweenLabels : datapointsCoordinate.f - clickableRadius;


            float top = datapointsCoordinate.s - clickableRadius;

            float right = clickableRadius > halfWidthBetweenLabels ? datapointsCoordinate.f + halfWidthBetweenLabels : datapointsCoordinate.f + clickableRadius;

            float bottom = datapointsCoordinate.s + clickableRadius;
            frames.add(new Frame(left, top, right, bottom));

        }
        return frames;
    }
}
